package com.tts.hbdao;

import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;

import com.tts.hbentity.Government;

/**
 * Data access object (DAO) for domain model class Government.
 * 
 * @see com.tts.hbentity.Government
 * @author MyEclipse Persistence Tools
 */

public class GovernmentDAO extends BaseHibernateDAO {
	private static final Log log = LogFactory.getLog(GovernmentDAO.class);
	// property constants
	public static final String GOVERNMENT_ADDRESS = "governmentAddress";
	public static final String GOVERNMENT_TEL = "governmentTel";
	public static final String GOVERNMENT_MANAGER = "governmentManager";
	public static final String GOVERNMENT_MANAGER_EMAIL = "governmentManagerEmail";
	public static final String GOVERNMENT_MANAGER_PWD = "governmentManagerPwd";

	public void save(Government transientInstance) {
		log.debug("saving Government instance");
		try {
			getSession().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(Government persistentInstance) {
		log.debug("deleting Government instance");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public Government findById(java.lang.String id) {
		log.debug("getting Government instance with id: " + id);
		try {
			Government instance = (Government) getSession().get(
					"com.tts.hbdao.Government", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(Government instance) {
		log.debug("finding Government instance by example");
		try {
			List results = getSession().createCriteria(
					"com.tts.hbdao.Government").add(Example.create(instance))
					.list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding Government instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from Government as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByGovernmentAddress(Object governmentAddress) {
		return findByProperty(GOVERNMENT_ADDRESS, governmentAddress);
	}

	public List findByGovernmentTel(Object governmentTel) {
		return findByProperty(GOVERNMENT_TEL, governmentTel);
	}

	public List findByGovernmentManager(Object governmentManager) {
		return findByProperty(GOVERNMENT_MANAGER, governmentManager);
	}

	public List findByGovernmentManagerEmail(Object governmentManagerEmail) {
		return findByProperty(GOVERNMENT_MANAGER_EMAIL, governmentManagerEmail);
	}

	public List findByGovernmentManagerPwd(Object governmentManagerPwd) {
		return findByProperty(GOVERNMENT_MANAGER_PWD, governmentManagerPwd);
	}

	public List findAll() {
		log.debug("finding all Government instances");
		try {
			String queryString = "from Government";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public Government merge(Government detachedInstance) {
		log.debug("merging Government instance");
		try {
			Government result = (Government) getSession().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(Government instance) {
		log.debug("attaching dirty Government instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(Government instance) {
		log.debug("attaching clean Government instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}